#include "Popup/Popup_giftParcel_2.h"
#include "Util/ImageManager.h"
#include "Util/SoundManager.h"

USING_NS_CC;

bool Popup_giftParcel_2::init()
{
	if (!CCLayerColor::initWithColor(ccc4(0,0,0,0)))
	{
		return false;
	}

	winSize = CCDirector::sharedDirector()->getWinSize();

	mainLayer = CCLayer::create();
	mainLayer->setPosition(ccp(-winSize.width,0));
	this->addChild(mainLayer);

	bg_block = CCSprite::create("charge_gift_bg_2.png");
	bg_block->setAnchorPoint(ccp(0,0));
	mainLayer->addChild(bg_block);

	btn_ok = ImageManager::getSpriteWithXml2(kImageSheet_freemium,"button_ok_small");
	btn_ok->setAnchorPoint(ccp(0.5f,0.0f));
	btn_ok->setPosition(ccp(160,80));
	mainLayer->addChild(btn_ok);

	btn_close = ImageManager::getSpriteWithXml2(kImageSheet_freemium,"button_close");
	btn_close->setPosition(ccp(290,420));
	mainLayer->addChild(btn_close);

	return true;
}



void Popup_giftParcel_2::openPopup(){
	mainLayer->setPosition(ccp(-winSize.width, 0));
	CCMoveTo *move = CCMoveTo::create(0.2, ccp(0,0));
	CCEaseExponentialOut* accel = CCEaseExponentialOut::create(move);
	mainLayer->runAction(accel);

	CCFadeTo* fade = CCFadeTo::create(0.2, 200);
	this->runAction(fade);
	SoundManager::PlaySoundEffect(sndEffect_zoomin);
}


void Popup_giftParcel_2::closePopup(){
	CCMoveTo *move = CCMoveTo::create(0.2, ccp(-winSize.width,0));
	CCEaseExponentialIn* accel = CCEaseExponentialIn::create(move);
	mainLayer->runAction(accel);

	CCFadeTo* fade = CCFadeTo::create(0.2, 0);
	CCCallFunc *cf = CCCallFunc::create(this,callfunc_selector(Popup_giftParcel_2::removeFromParent));
	this->runAction(CCSequence::create(fade,cf,NULL));
	SoundManager::PlaySoundEffect(sndEffect_zoomout);
}



int Popup_giftParcel_2::touchEnded(CCPoint pt){

	if (btn_close->boundingBox().containsPoint(pt))
	{
		return giftParcel_2_btn_close;
	}

	else if (btn_ok->boundingBox().containsPoint(pt))
	{
		return giftParcel_2_btn_ok;
	}

	return -1;
}